package cn.m3a1.creditsystem.util;

import cn.m3a1.creditsystem.bean.SchoolSchedule;
import cn.m3a1.creditsystem.bean.SchoolScheduleModel;
import cn.m3a1.creditsystem.bean.StudentSchedule;
import cn.m3a1.creditsystem.bean.StudentScheduleModel;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wyj
 * @date 2020/2/10
 * @time 上午8:48
 */
public class MyUtil {
    public List<SchoolScheduleModel> getSchoolScheduleModel(SchoolSchedule schedule){
        if (schedule.getTime().isEmpty()){
            return  null;
        }
        List<SchoolScheduleModel> list =new ArrayList<>();
        String str1=schedule.getTime();
        String[] strs1 = str1.split(";");
        for (String str2 : strs1) {
            String[] strs2 = str2.split("\\{");
            String str3 = strs2[0];
            String str4 = strs2[1];
            String weekday=str3.substring(0, str3.indexOf("第"));
            //System.out.println(weekday);
            //System.out.println(str4);
            //System.out.println(str3.substring(str3.indexOf("第")+1, str3.lastIndexOf("节")));
            String weeks=str4.substring(str4.indexOf("第")+1, str4.indexOf("周"));
            int start_week=Integer.parseInt(weeks.split("-")[0]);
            int last_week=Integer.parseInt(weeks.split("-")[1]);
            String[] day_times=str3.substring(str3.indexOf("第")+1, str3.lastIndexOf("节")).split(",");
            for(int i=start_week;i<=last_week;i++) {
                for(int j=0;j<day_times.length;j++) {
                    SchoolScheduleModel schoolScheduleModel = new SchoolScheduleModel();
                    schoolScheduleModel.setSchoolScheduleId(schedule.getId());
                    schoolScheduleModel.setWeek(i);
                    schoolScheduleModel.setWeekDay(weekday);
                    schoolScheduleModel.setDayTime(Integer.parseInt(day_times[j]));
                    list.add(schoolScheduleModel);
                    //System.out.println("第"+i+"周"+weekday+"第"+day_times[j]);
                }
            }
        }


        return  list;
    }

    public List<StudentScheduleModel> getStudentScheduleModel(StudentSchedule studentSchedule){
        if (studentSchedule.getTime().isEmpty()){
            return  null;
        }
        List<StudentScheduleModel> list =new ArrayList<>();
        String str1=studentSchedule.getTime();
        String[] strs1 = str1.split(";");
        for (String str2 : strs1) {
            String[] strs2 = str2.split("\\{");
            String str3 = strs2[0];
            String str4 = strs2[1];
            String weekday=str3.substring(0, str3.indexOf("第"));
            //System.out.println(weekday);
            //System.out.println(str4);
            //System.out.println(str3.substring(str3.indexOf("第")+1, str3.lastIndexOf("节")));
            String weeks=str4.substring(str4.indexOf("第")+1, str4.indexOf("周"));
            int start_week=Integer.parseInt(weeks.split("-")[0]);
            int last_week=Integer.parseInt(weeks.split("-")[1]);
            String[] day_times=str3.substring(str3.indexOf("第")+1, str3.lastIndexOf("节")).split(",");
            for(int i=start_week;i<=last_week;i++) {
                for(int j=0;j<day_times.length;j++) {
                    StudentScheduleModel studentScheduleModel = new StudentScheduleModel();
                    studentScheduleModel.setStudentId(studentSchedule.getStudentId());
                    studentScheduleModel.setWeek(i);
                    studentScheduleModel.setWeekDay(weekday);
                    studentScheduleModel.setDayTime(Integer.parseInt(day_times[j]));
                    list.add(studentScheduleModel);
                    //System.out.println("第"+i+"周"+weekday+"第"+day_times[j]);
                }
            }
        }


        return  list;
    }

    public Boolean CompareSchoolSchedule(SchoolSchedule schedule,SchoolSchedule schedule2){
        List<SchoolScheduleModel> schoolScheduleModel1 = getSchoolScheduleModel(schedule);
        List<SchoolScheduleModel> schoolScheduleModel2 = getSchoolScheduleModel(schedule2);
        for (SchoolScheduleModel sc1:schoolScheduleModel1
             ) {
            for (SchoolScheduleModel sc2:
                    schoolScheduleModel2) {
                if (sc1.getWeek().equals(sc2.getWeek())&&sc1.getWeekDay().equals(sc2.getWeekDay())&&sc1.getDayTime().equals(sc2.getDayTime())){
                    return false;
                }
            }
        }
        return true;
    }
}
